#!/usr/bin/env python
# -*- coding: utf-8 -*-
import  base
from src.model.models import User
from src.dao.daos import MsgDao
class Msg(base.BaseAction):
    def _get(self):
    	json=self.request.get('json')
    	if 'json'!=json:
        	self.go(None,'msg.htm') 
        else:
        	dao=MsgDao()
	    	name = self.request.cookies.get('name')
	    	type = self.request.get('type') 
	    	if(type=='' or type == None):
	    		type='toUser'
	    	#print type+"-"+name	
	    	msgs = dao.query({''+type:name});
	    	
	    	#print len(mm)
	        json=self.json(['content','title','date','fromUser','toUser'],msgs)
	        _values_ = {
	           'json': json
	         }
	        self.go(_values_,'info.htm') 
        
class AddMsg(base.BaseAction):
    def _get(self):
    	_values_ = {
           'json': ''
        }
    	self.go(_values_,'msg/addMsg.htm') 
        
    def post(self):
        dao=MsgDao()
        title=self.request.get('title')
        content=self.request.get('content')
        toUser=self.request.get('toUser')
        name=self.request.cookies.get('name')  
        #print title+","+content+","+toUser
        dao.insert(title,content,name,toUser)
        json='{success:"Y"}'
        _values_ = {
           'json':json 
         }
        self.go(_values_,'info.htm') 
       